using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class Admin_Branch : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        try
        {
            // New connection
            Connection newCon = new Connection();
            SqlConnection con = newCon.ConStr;

            // open conneciton
            con.Open();

            // prepare command
            SqlCommand cmd = new SqlCommand("insert into Branch values(@name , @add , @pin)", con);

            cmd.Parameters.AddWithValue("name", TextBox1.Text);
            cmd.Parameters.AddWithValue("add", TextBox2.Text);
            cmd.Parameters.AddWithValue("pin", DropDownList1.SelectedItem.Value);

            // execute query
            cmd.ExecuteNonQuery();

            // reload gridview
            GridView1.DataBind();

            // close connection
            con.Close();
            Label1.Text = "";
        }
        catch(Exception ex)
        {
            Label1.Text = "Cannot insert new record: " + ex.Message;
        }
    }
}
